package cn.e2win.biz.notice;

import cn.e2win.base.controller.MyException;
import cn.e2win.base.entity.SysLabel;
import cn.e2win.base.json.vo.Pager;
import cn.e2win.base.json.vo.Result;
import cn.e2win.biz.annotation.PageParam;
import cn.e2win.biz.base.BaseController;
import cn.e2win.biz.base.BaseService;
import cn.e2win.biz.base.CommonService;
import cn.e2win.biz.dbo.DsEmp;
import cn.e2win.biz.dbo.Notice;
import cn.e2win.biz.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@Controller
@Scope("request")
@RequestMapping("/m")
public class NoticeControllerM extends NoticeController {

	@Autowired
	private NoticeService noticeService;
	@Autowired
	private CommonService commonService;
	
	@Override
	public BaseService initService() {
		return noticeService;
	}

	@RequestMapping("newsDetail")
	public String newsDetail(HttpServletRequest request, @RequestParam("noticeType") String noticeType, ModelMap modelMap){
		try {
			pager.getScMap().put("noticeType",noticeType);
			pager.getScMap().put("toUserId",pager.getCurrUser().getId()+"");
			noticeService.pagerNotice(pager);
			modelMap.put("noticeType",noticeType);
			String typeDesc = "";
			if(noticeType.equals("ACTIVITY")){
                typeDesc = "活动消息";
            }else if(noticeType.equals("APPROVE")){
                typeDesc = "审批消息";
            }
			modelMap.put("typeDesc",typeDesc);
			modelMap.put("pager", pager);
			return "m/newsDetail";
		} catch (Exception e) {
			return "m/login";
		}
	}

	@RequestMapping("newsPager")
	@ResponseBody
	public Pager newsPager(HttpServletRequest request, @RequestParam("noticeType") String noticeType, ModelMap modelMap){
		String pageNum = request.getParameter("pageNum");
		if(StringUtils.isEmpty(pageNum)){

		}else{
			pager.setPageNum(Integer.parseInt(pageNum));
		}
		pager.getScMap().put("noticeType",noticeType);
		pager.getScMap().put("toUserId",pager.getCurrUser().getId()+"");
		noticeService.pagerNotice(pager);
		return pager;
	}


	@RequestMapping("news")
	public String news(HttpServletRequest request, ModelMap modelMap){
		try {
			pager.getScMap().put("noticeType","APPROVE");
			pager.getScMap().put("readStatus","unRead");
			pager.getScMap().put("toUserId",pager.getCurrUser().getId()+"");
			noticeService.pagerNotice(pager);
			Integer approveCount = pager.getTotalCount();
			modelMap.put("approveCount", approveCount);
		} catch (Exception e) {
			return "m/login";
		}
		return "m/news";
	}

	@RequestMapping("readMessage/{id}")
	public String readMessage(HttpServletRequest request, ModelMap modelMap,@PathVariable(ID)Integer id) throws MyException {
		return super.readMessage(request,modelMap,id);
	}


}
